package com.example.templatedemo

import com.example.lib_common.base.BaseHttpViewModel
import com.example.lib_common.http.server.CommonOtherServer
import com.example.lib_common.http.server.CommonOtherServer2
import com.example.lib_common.http.RetrofitManager
import com.example.lib_common.http.httpRequest
import com.example.lib_common.http.liveRequest
import com.example.lib_common.logger.Logger

class MainVM : BaseHttpViewModel<CommonOtherServer>() {
    var a = 10
    val myServer by lazy { RetrofitManager.create(CommonOtherServer2::class.java) }

    fun getBanners() = liveRequest({ httpRepository.banner() }) {
//        onStart = {
//            // 请求开始，显示 Loading
//            Logger.d("onStart")
//        }
//        onSuccess = { data ->
//            // 请求成功
//            Logger.d("onSuccess ${data?.size}")
//        }
//        onFailed = { ex ->
//            // 请求失败
//            Logger.d("onFailed ${ex.message}")
//        }
//        onFinally = {
//            // 请求结束，隐藏 Loading
//            Logger.d("onFinally")
//        }
    }


    fun getH5Url() {
        httpRequest(httpRepository::banner) {
            onStart = {
                // 请求开始，显示 Loading
                Logger.d("onStart")
            }
            onSuccess = { data ->
                // 请求成功
                Logger.d("onSuccess ${data?.size}")
            }
            onFailed = { ex ->
                // 请求失败
                Logger.d("onFailed ${ex.message}")
            }
            onFinally = {
                // 请求结束，隐藏 Loading
                Logger.d("onFinally")
            }
        }
    }

    override fun getBaseUrl(): String? {
        return "https://www.wanandroid.com"
    }
}